package com.easysale.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.easysale.domain.Category;

@Repository
public class CategoryDAOImpl implements CategoryDAO {
	@Autowired
	SessionFactory sessionFactory;
	
	@Override
	public void addCategory(Category category) {
		sessionFactory.getCurrentSession().save(category);
	}

	@Override
	public List<Category> categories() {
		return sessionFactory.getCurrentSession().createQuery("from Category").list();
	}

	@Override
	public void deleteCategory(Integer CategoryId) {
		Category cat = (Category)sessionFactory.getCurrentSession().load(Category.class, CategoryId);
		if(cat != null) sessionFactory.getCurrentSession().delete(cat);
	}

}
